<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <div>用户名：<input type="text" id="username" /></div>
  <div>密码:<input type="text" id="password" /></div>
  <div>
    <button id="login">登录</button>
  </div>
  <body>
    <script>
      // 先获取用户名、密码
      var uservalue = localStorage.getItem('username')
      var passvalue = localStorage.getItem('password')
      if (uservalue && passvalue) {
        username.value = uservalue
        password.value = passvalue
      }
      login.onclick = function () {
        console.log(username.value, password.value)
        localStorage.setItem('username', username.value)
        localStorage.setItem('password', password.value)
      }
    </script>
  </body>
</html>
